package org.csu.gp_store.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.csu.gp_store.entity.BrowsingHistory;
import org.csu.gp_store.mapper.BrowsingHistoryMapper;
import org.csu.gp_store.service.BrowsingHistoryService;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrowsingHistoryServiceImpl implements BrowsingHistoryService {

    @Autowired
    private BrowsingHistoryMapper browsingHistoryMapper;

    @Override
    public int insertBrowsingHistory(@NotNull Long accountID, @NotNull Long productID) {
        BrowsingHistory browsingHistory =new BrowsingHistory();
        browsingHistory.setAccountID(accountID);
        browsingHistory.setProductID(productID);
        return browsingHistoryMapper.insert(browsingHistory);

    }

    @Override
    public int deleteBrowsingHistory(@NotNull Long accountID, @NotNull Long productID) {
        QueryWrapper<BrowsingHistory>queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("accountID",accountID).eq("productID",productID);
        return browsingHistoryMapper.delete(queryWrapper);
    }


    @Override
    public List<BrowsingHistory> getBrowsingHistoryByAccountID(@NotNull Long accountID) {
        QueryWrapper<BrowsingHistory>queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("accountID",accountID);
        return  browsingHistoryMapper.selectList(queryWrapper);
    }
}
